﻿using SalesPages.DomainModel;
using SalesPages.DomainModel.SearchCriteria;
using SalesPages.DomainModel.ViewModel;
using SalesPages.Infrastructure.IManager;
using SalesPages.WebApi.App_Start;
using SalesPagesDemo.Common.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace SalesPages.WebApi.Controllers
{
    public class ContactUsController : ApiController
    {
        private IContactUsManager contactUsManager;

        public ContactUsController(IContactUsManager contactUsManager)
        {
            this.contactUsManager = contactUsManager;
        }

        /// <summary>
        /// select leads by user name
        /// </summary>
        /// <param name="userName">user name</param>
        /// <returns></returns>
        [HttpGet, ActionCache]
        public PageList<ContactUs> Get(string userName,int pageIndex)
        {
            var criteria = new ContactUsSearchCriteria();
            criteria.FirstName = userName;
            criteria.NeedPaging = true;
            criteria.Page = pageIndex;

           return new PageList<ContactUs>
           {
               ListItem = contactUsManager.Search(criteria),
               CurrentIndex = pageIndex,
               TotalPage =criteria.TotalPages,
               TotalCount = criteria.TotalCount
           };
        }

       
        /// <summary>
        /// Add leads
        /// </summary>
        /// <param name="value"></param> 
        [HttpPost]
        public void Post(ContactUs contactUs)
        {
            contactUsManager.Add(contactUs);
        }

        /// <summary>
        /// Delete Leads
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete]//253624
        public void Delete(int id)
        {
            contactUsManager.Delete(id);
        }
    }
}
